<?php


$data = $_POST;

// 取数据文件里面的原数据
$oldData = file_get_contents("./db/user.txt");
// 把原来的数据转成数组
$oldData = json_decode($oldData,true);

// 循环所有用户
foreach ($oldData as  $user) {
	if($user['username']==$data['username'] && $user['password']==md5($data['password'])){

		session_start();
		// 写session
		$_SESSION['username'] = $data['username'];

		exit(json_encode(['code'=>0,'msg'=>'登录成功']));
	}
}

exit(json_encode(['code'=>1,'msg'=>'用户或者密码不正确']));
